package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 物资来源
 * @Author: Mr.Cao
 * @DateTime: 2021/11/9 15:08
 * BMW F750GS
 **/
@RestController
@RequestMapping("business/supplier/")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;


    /**
     * 分页获取物资来源
     * */
    //http://www.localhost:8989/business/supplier/findSupplierList?pageNum=1&pageSize=10&name=
    @GetMapping("findSupplierList")
    public ResponseBean findSupplierList(@RequestParam Map queryMap){
        System.out.println("分页获取物资来源 = " + queryMap.toString());
        PageVO supplierList = supplierService.findSupplierList(queryMap);
        return ResponseBean.success(supplierList);
    }
    /**
     * 添加物资来源
     * */
    //http://www.localhost:8989/business/supplier/add1
    @PostMapping("add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        supplierService.add(supplierVO);
        return ResponseBean.success();
    }
    /**
     * 编辑物资来源时,数据的回显
     * */
    //http://www.localhost:8989/business/supplier/edit/25
    @GetMapping("edit/{Id}")
    public ResponseBean edit(@PathVariable long Id){
        SupplierVO supplierVO =  supplierService.edit(Id);
        return ResponseBean.success(supplierVO);
    }
    /**
     * 删除物资来源
     * */
    //http://www.localhost:8989/business/supplier/delete/23
    @DeleteMapping("delete/{Id}")
    public ResponseBean delete(@PathVariable long Id){
        supplierService.delete(Id);
        return ResponseBean.success();
    }
    /**
     * 更新物资来源
     * */
    //http://www.localhost:8989/business/supplier/update/23
    @PutMapping("update/{Id}")
    public ResponseBean update(@PathVariable long Id,@RequestBody SupplierVO supplierVO){
        supplierService.update(Id,supplierVO);
        return ResponseBean.success();
    }
    /**
     * 查询全部物资来源
     * */
    //http://www.localhost:8989/business/supplier/findAll
    @GetMapping("findAll")
    public ResponseBean findAll(){
       List list =  supplierService.findAll();
        return ResponseBean.success(list);
    }
}
